<?php 
// 
// Por Ricardo Costa - ricardo.community@globo.com - 2002 
// Classe para insercao e exibicao do log 
// 
//  log 
//    +---- log( Nome do arquivo de log ) // Inicializa o log passando o nome do arquivo 
//    +---- addLog( String para insercao, Tipo de mensagem [error, sucess] )  //  Adicionar uma linha ao arquivo de Log 
//    +---- show() //  Exibir a o conteudo do log 
// 
// 

class log { 
   var $filename; // Caminho e nome do arquivo de log 



   # Inicializa o log passando o nome do arquivo ############################################# Revis?o 02/09/2002 # 
   function log($filename = NULL) { 

      if (!isset($GLOBALS["nyear"])) 
         $this->filename = date("Y.m.d").".log"; 
      else     
         $this->filename = $GLOBALS["nyear"].".".mformat(2, $GLOBALS["nmonth"]).".".mformat(2, $GLOBALS["nday"]).".log"; 
   } 
   # Inicializa o log passando o nome do arquivo ############################################# Revis?o 02/09/2002 # 




   # Adicionar uma linha ao arquivo de Log ################################################### Revis?o 02/09/2002 # 
   function addLog($text, $type) { 

//      $log_file = @fopen($this->filename, "a+"); 
//      if ($log_file) { 
////         $log = fread($log_file, filesize($log_file));
////			$handle = fopen($log_file,'wb');
//			$content = "";
//			while (!feof($log_file)) {
//			  $content .= fread($log_file, 8192);
//			}
////         $content = $log; 
////         $ini = strlen($GLOBALS["REQUEST_URI"]) - 40; 
//         $content .= "<span class=\"$type\"> - ". 
//                       date("Y.m.d ..... H:m:s")." ..... ". 
//                       str_pad(substr($_SERVER['REMOTE_ADDR']." ", 0, 15), 5, ".", STR_PAD_RIGHT)." ". 
//                       str_pad($GLOBALS["user_name"], 5, ".", STR_PAD_RIGHT). 
//                       str_pad(substr($_SERVER["PHP_SELF"], strrpos($_SERVER["PHP_SELF"], "/"), strlen($_SERVER["PHP_SELF"])), 5, ".", STR_PAD_RIGHT). 
//                        " $text</span><br>\n"; 
//         fputs($log_file, $content); 
//         fclose($log_file); 
//      } 
   } 
   # Adicionar uma linha ao arquivo de Log ################################################### Revis?o 02/09/2002 # 




   # Exibir a o conteudo do log ############################################################## Revis?o 02/09/2002 # 
   function show() { 

      if ($log_file = @fopen($this->filename, "r")) { 

         while (!feof ($log_file)) { 
            $buffer = fgets($log_file, 4096); 
            if (strpos($buffer, $GLOBALS["nday"].".".mformat(2, $GLOBALS["nmonth"]).".".$GLOBALS["nyear"]) > 1) { 
               $buffer = str_replace("\\\"", "\"", $buffer); 
               print($buffer); 
               flush(); 
            } 
         } 

         fclose ($log_file); 
      } 
      else 
          print("Error on open a log \"$this->filename\""); 
   } 
   # Exibir a o conteudo do log ############################################################## Revis?o 02/09/2002 # 



} # Final da Classe 
?>